package com.cjm.util;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.UUID;

public class BigFileUtils {
    public static void main(String[] args) {
        generator(2048, "D:\\bigFile.txt");
    }

    @SuppressWarnings("all")
    public static void generator(int much, String location) {
        long start = System.currentTimeMillis();
        long fileSize = much * 1024 * 1024L;
        File file = new File(location);
        try (FileOutputStream out = new FileOutputStream(file)) {
            StringBuilder sb = new StringBuilder();
            if (!file.exists()) {
                file.createNewFile();
            } else {
                file.delete();
                file.createNewFile();
            }
            long count = 0L;
            while (count < fileSize) {
                String xx = UUID.randomUUID().toString();
                byte[] bytes = xx.getBytes(StandardCharsets.UTF_8);
                out.write(bytes);
                count += bytes.length;
            }
        } catch (Exception e) {
        }
        long end = System.currentTimeMillis();
        System.err.println("time = " + (end - start) / 1000 + " 秒");
    }
}
